﻿using Furion.SensitiveDetection;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FurStudy.Core
{
    /// <summary>
    /// 数据脱敏检测类
    /// 通过ISensitiveDetectionProvider服务使用进行手动脱敏验证处理
    /// </summary>
    public class SensitiveDetectionDemo
    {
        private readonly ISensitiveDetectionProvider _sensitiveDetectionProvider;

        public SensitiveDetectionDemo(ISensitiveDetectionProvider sensitiveDetectionProvider)
        {
            _sensitiveDetectionProvider = sensitiveDetectionProvider;
        }

        /// <summary>
        /// 获取所有脱敏词汇
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<string>> GetWordsAsync()
        {
            return await _sensitiveDetectionProvider.GetWordsAsync();
        }

        /// <summary>
        /// 判断是否是正常的词汇
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public async Task<bool> VaildedAsync(string text)
        {
            return await _sensitiveDetectionProvider.VaildedAsync(text);
        }

        /// <summary>
        /// 替换非正常词汇
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public async Task<string> ReplaceAsync(string text)
        {
            return await _sensitiveDetectionProvider.ReplaceAsync(text, '*');
        }
    }

    /// <summary>
    /// 实现数据验证脱敏检测[SensitiveDetection]
    /// </summary>
    public class Content
    {
        /// <summary>
        /// 在属性中使用
        /// </summary>
        [SensitiveDetection('*')] // 替换脱敏词汇的特性支持(当前特性支持仅支持类不支持方法的单个值)
        public string Text { get; set; }

        /// <summary>
        /// 在动态API/Controller中使用
        /// </summary>
        /// <param name="text"></param>
        public void Test([SensitiveDetection] string text)
        {

        }
    }
}
